home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_172_mc_potion / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  1.2 KB  |  66 lines

  1. this.onEnterFrame = function()
  2. {
  3.    onFall();
  4.    this._x -= _hitomi.speed;
  5.    if(_hitomi.hitTest(this._x,this._y - 30,true))
  6.    {
  7.       _hitomi.hp += random(15) + 15;
  8.       delete this.onEnterFrame;
  9.       play();
  10.    }
  11. };
  12. init = function()
  13. {
  14.    gravity = 4;
  15.    time = getTimer();
  16.    time /= 100;
  17.    rot = random(21) - 10;
  18.    _rotation = 0;
  19.    floor = _parent.floor;
  20.    bounce = 0.22;
  21.    speedx = random(7) - 3;
  22.    speedystart = 0;
  23.    _init = true;
  24. };
  25. this.onFall = function()
  26. {
  27.    if(!_init)
  28.    {
  29.       init();
  30.    }
  31.    timenow = getTimer();
  32.    timenow /= 100;
  33.    speedy = gravity * (timenow - time) + speedystart;
  34.    this._x += speedx / 5;
  35.    this._y += speedy / 5;
  36.    if(this._y > floor)
  37.    {
  38.       this._y = floor;
  39.       speedy *= - bounce;
  40.       time = getTimer();
  41.       time /= 100;
  42.       rot *= -0.5;
  43.       speedystart = speedy;
  44.    }
  45.    if(speedy < 1 && _Y + 2 > floor)
  46.    {
  47.       speedx = 0;
  48.       this.onRotate = function()
  49.       {
  50.          if(_rotation % 360 > 180)
  51.          {
  52.          }
  53.          if(Math.abs(_rotation) < 2)
  54.          {
  55.             delete this.onRotate;
  56.          }
  57.       };
  58.    }
  59.    onRotate();
  60. };
  61. if(!_init)
  62. {
  63.    init();
  64. }
  65. stop();
  66.